<script lang="ts" setup>
import { webImgs } from "@/hooks/images";
</script>

<template>
  <div class="CssExam">
    <div class="triangle"></div>
    <p class="px8"><span>相逢已是上上签</span> <span>何须相思煮余年</span></p>
    <div class="template">
      <h3>模版</h3>
      <div class="contain">
        <div :class="'box box' + inx" v-for="inx in 4" :key="inx"></div>
      </div>
    </div>
    <div class="template">
      <h3>品字布局</h3>
      <div class="contain pingLayout">
        <div :class="'box box' + inx" v-for="inx in 3" :key="inx">
          <div class="li"></div>
          <div class="li"></div>
          <div class="li"></div>
        </div>
      </div>
    </div>
    <div class="template">
      <h3>两列布局（左侧固定 右侧自适应）</h3>
      <div class="contain twocolumn">
        <div :class="'box box' + inx" v-for="inx in 4" :key="inx">
          <div class="left"></div>
          <div class="right"></div>
        </div>
      </div>
    </div>
    <div class="template">
      <h3>水平垂直居中</h3>
      <div class="contain horizon_vertical">
        <div :class="'box box' + inx" v-for="inx in 5" :key="inx">
          <div class="center"><img :src="webImgs[0]" alt="" /></div>
        </div>
      </div>
    </div>
    <div class="template">
      <h3>清除浮动</h3>
      <div class="contain clearFloat">
        <div :class="'box box' + inx" v-for="inx in 4" :key="inx">
          <div class="ul">
            <div class="li" v-for="v in 4" :key="v"></div>
          </div>
          <div class="ll">相逢何必曾相识</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.CssExam {
  padding: 16px;

  .px8 {
    // font-size: 12px;
    // transform: scale(0.5);
    // transform-origin: left top;
    font-size: 24px;
    &::first-letter {
      color: pink;
    }
  }

  /* 把上、右、左、三条边隐藏掉（颜色设为 transparent） */
  .triangle {
    width: 100px;
    height: 0;
    border: 30px solid;
    border-color: pink skyblue orangered purple;
  }

  .template {
    margin-bottom: 20px;
    border-bottom: 2px solid skyblue;
    h3 {
      font-weight: 600;
    }
    .contain {
      display: flex;
      height: 160px;
      margin: 10px 0;
      .box {
        width: 200px;
        height: 100%;
        margin-right: 10px;
        background-color: skyblue;
      }
    }
  }

  .template .pingLayout {
    .box {
      .li {
        width: 50%;
        height: 50%;
        border: 1px solid orangered;
        &:first-child {
          width: 100%;
        }
      }
    }
    .box1 .li {
      float: left;
    }
    .box2 {
      display: flex;
      flex-wrap: wrap;
    }
    .box3 {
      font-size: 0; // 去除行内块空隙
      .li {
        display: inline-block;
      }
    }
  }

  .template .twocolumn {
    .box {
      position: relative;
      padding: 4px;
      .left {
        height: 100%;
        background-color: pink;
      }
      .right {
        height: 100%;
        background-color: orangered;
      }
    }
    .box1 {
      .left {
        float: left;
        width: 80px;
      }
    }
    .box2 {
      .left {
        position: absolute;
        top: 0;
        width: 80px;
      }
    }
    .box3 {
      .right {
        position: absolute;
        top: 0;
        left: 80px;
        right: 0;
      }
    }
    .box4 {
      display: flex;
      .left {
        width: 80px;
      }
      .right {
        flex: 1;
      }
    }
  }

  .template .horizon_vertical {
    .box {
      position: relative;
      img {
        width: 120px;
      }
    }
    .box2 {
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .box3 img {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }
    .box4 img {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .box5 {
      display: table;
      .center {
        display: table-cell;
        text-align: center;
        vertical-align: middle;
      }
    }
  }

  .template .clearFloat {
    .box {
      .ul .li {
        float: left;
        width: 90px;
        height: 40px;
        margin-right: 10px;
        margin-bottom: 10px;
        background-color: pink;
      }
      .ll {
        width: 100px;
        height: 60px;
        color: white;
        background-color: orangered;
      }
    }
    .box2 .ul {
      &::after {
        content: "";
        display: block;
        clear: both;
      }
    }
    .box3 .ul {
      overflow: hidden;
    }
    .box4 .ul {
      height: 100px;
    }
  }
}
</style>
